<?php

require_once WP_PLUGIN_DIR . '/diapucp-events/defines.php' ;
require_once DPEM_SMB_PATH . '/smb_basefield.php' ;

class smartmeta_radio extends smb_basefieldbox {
   public function  __construct($fields){
        $this->set_fields($fields);
        $this->set_inputid( $fields['id'] . '_radio_field' );
   }

   public static function build_me( $fields, &$new_field_object ){
        $new_field_object = new smartmeta_radio($fields);
   }

    public function show(){
        $value = $this->fetch_value();
        ?>
            <td>
                <label for="<?php echo $this->inputid; ?>"><?php echo $this->fields['name']; ?></label>
            </td>
            <td>
            <?php foreach($this->fields['options'] as $opt_value=>$opt_name): ?>
                    <label>
                        <input
                            type="radio"
                            name="<?php echo $this->inputid; ?>"
                            id="<?php echo $this->inputid; ?>_<?php echo $opt_value; ?>"
                            value="<?php echo $opt_value?>"
                            <?php checked($value, $opt_value)?>
                        />
                        <?php echo $opt_name ?>
                    </label>
                    <br />
            <?php endforeach ?>
            </td>
        <?php
    }

   public function save($post_id){
        $data = $_POST[ $this->inputid ];
        if ( empty( $data ) and isset($this->fields['default'] ) ){ $data = $this->fields['default']; }
        $data = wp_strip_all_tags($data);
        smb_basefieldbox::set($this->fields['id'], $data);
   }

}
?>




